defmodule ProgContest.DockerImagesTest do
  use ProgContest.DataCase
  use ProgContest.Fixtures

  setup do
    [quiz: contest_fixture() |> quiz_fixture()]
  end

  describe "docker_images" do
    alias ProgContest.DockerImages.DockerImage

    test "list_docker_images/0 returns all docker_images", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert DockerImages.list_docker_images() == [docker_image]
    end

    test "get_docker_image!/1 returns the docker_image with given id", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert DockerImages.get_docker_image!(docker_image.id) == docker_image
    end

    test "create_docker_image/1 with valid data creates a docker_image", %{quiz: quiz} do
      attrs = Map.put(@valid_docker_image_attrs, :quiz_id, quiz.id)
      assert {:ok, %DockerImage{} = docker_image} = DockerImages.create_docker_image(attrs)
      assert docker_image.image_id == @valid_docker_image_attrs.image_id
      assert docker_image.language == @valid_docker_image_attrs.language
    end

    test "create_docker_image/1 with invalid data returns error changeset" do
      assert {:error, %Ecto.Changeset{}} = DockerImages.create_docker_image(@invalid_docker_image_attrs)
    end

    test "update_docker_image/2 with valid data updates the docker_image", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert {:ok, %DockerImage{} = docker_image} = DockerImages.update_docker_image(docker_image, @update_docker_image_attrs)
      assert docker_image.image_id == @update_docker_image_attrs.image_id
      assert docker_image.language == @update_docker_image_attrs.language
    end

    test "update_docker_image/2 with invalid data returns error changeset", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert {:error, %Ecto.Changeset{}} = DockerImages.update_docker_image(docker_image, @invalid_docker_image_attrs)
      assert docker_image == DockerImages.get_docker_image!(docker_image.id)
    end

    test "delete_docker_image/1 deletes the docker_image", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert {:ok, %DockerImage{}} = DockerImages.delete_docker_image(docker_image)
      assert_raise Ecto.NoResultsError, fn -> DockerImages.get_docker_image!(docker_image.id) end
    end

    test "change_docker_image/1 returns a docker_image changeset", %{quiz: quiz} do
      docker_image = docker_image_fixture(quiz)
      assert %Ecto.Changeset{} = DockerImages.change_docker_image(docker_image)
    end
  end
end
